package Client;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.sql.Date;
import java.util.List;

import Admin.EditAccount;
import GroupClass.ConnectRMI;
import Project_etow.EtowInterface;

public class MyProfiles extends javax.swing.JDialog {
    
    ConnectRMI connectRMI = new ConnectRMI();
    private String chua1, chua2;
    private String companyname;

    public MyProfiles(java.awt.Frame parent, boolean modal, String accid, String groupname) {
        super(parent, modal);
        chua1 = accid;
        chua2 = groupname;      
        initComponents();
    }

    @SuppressWarnings("unchecked")
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        flgroupname = new javax.swing.JLabel();
        flloginname = new javax.swing.JLabel();
        flpassword = new javax.swing.JLabel();
        editpass = new javax.swing.JButton();
        btnUnit = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        flcmnd = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        flname = new javax.swing.JLabel();
        flsex = new javax.swing.JLabel();
        flbirthday = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        fladdress = new javax.swing.JLabel();
        flnumber = new javax.swing.JLabel();
        flemail = new javax.swing.JLabel();
        editprofiles = new javax.swing.JButton();
        flcompaname = new javax.swing.JLabel();
        btexit = new javax.swing.JButton();

        String GroupName = chua2;

        String login = "loginN";
        String name = "Full Name";
        companyname = "Company Name";
        String birthday = "Birthday";
        String sex = "Gender";
        String cmnd = "CMND";
        String address = "Address";
        String phone = "Phone Number";
        String email = "Email";

        try {
            Registry registry = LocateRegistry.getRegistry(connectRMI.host, connectRMI.port);
            EtowInterface obj = (EtowInterface) registry.lookup(connectRMI.regis);            

            List<GroupClass.AccountClass> x = obj.ShowMyProfiles(Integer.parseInt(chua1));

            for (GroupClass.AccountClass d : x) {

                login = d.getLoginname();
                name = d.getName();
                companyname = d.getCompanyName();
                System.out.println(companyname);
                birthday = d.getBirthday();
                sex = d.getSex();
                cmnd = d.getCmnd();
                address = d.getAddress();
                phone = d.getPhone();
                email = d.getEmail();

            }

        } catch (Exception ex) {
            ex.printStackTrace();
        }

        setLocation(400, 100);
        setUndecorated(true);
        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("My Profiles");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Account Information"));

        jLabel3.setText("Password :");

        jLabel2.setText("Login Name :");

        jLabel1.setText("Group Name :");

        flgroupname.setText(GroupName);

        flloginname.setText(name);

        flpassword.setText("********");
        btexit.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                setVisible(false);

            }
        });
        editpass.setText("Change password");
        editpass.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editpassActionPerformed(evt);
            }
        });

        btnUnit.setText("My Unit");
        btnUnit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUnitActionPerformed(evt);
            }
        });
        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout
                .setHorizontalGroup(jPanel1Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(
                                jPanel1Layout
                                        .createSequentialGroup()
                                        .addContainerGap()
                                        .addGroup(
                                                jPanel1Layout
                                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(jLabel1).addComponent(jLabel2)
                                                        .addComponent(jLabel3))
                                        .addGap(18, 18, 18)
                                        .addGroup(
                                                jPanel1Layout
                                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addGroup(
                                                                jPanel1Layout.createSequentialGroup()
                                                                        .addComponent(flloginname).addContainerGap())
                                                        .addGroup(
                                                                jPanel1Layout
                                                                        .createSequentialGroup()
                                                                        .addComponent(flpassword)
                                                                        .addPreferredGap(
                                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                                                71, Short.MAX_VALUE)
                                                                        .addComponent(editpass))
                                                        .addGroup(
                                                                jPanel1Layout
                                                                        .createSequentialGroup()
                                                                        .addComponent(flgroupname)
                                                                        .addPreferredGap(
                                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                Short.MAX_VALUE).addComponent(btnUnit)))));
        jPanel1Layout
                .setVerticalGroup(jPanel1Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(
                                javax.swing.GroupLayout.Alignment.TRAILING,
                                jPanel1Layout
                                        .createSequentialGroup()
                                        .addGroup(
                                                jPanel1Layout
                                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(jLabel1).addComponent(flgroupname)
                                                        .addComponent(btnUnit))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(
                                                jPanel1Layout
                                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(jLabel2).addComponent(flloginname))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(
                                                jPanel1Layout
                                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(jLabel3).addComponent(flpassword)
                                                        .addComponent(editpass))));

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Information Testimonials"));

        jLabel4.setText("Identity card :");

        flcmnd.setText(cmnd);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(
                        jPanel2Layout.createSequentialGroup().addContainerGap().addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(flcmnd)
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
        jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(
                        jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel4).addComponent(flcmnd)));

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Personal Information"));

        jLabel6.setText("Full Name");

        jLabel7.setText("Gender");

        jLabel8.setText("Birthday");

        jLabel9.setText("Address");

        jLabel11.setText("Phone Number");

        flname.setText(name);

        flsex.setText(sex);

        flbirthday.setText(birthday);

        jLabel19.setText("Email :");

        fladdress.setText(address);

        flnumber.setText(phone);

        flemail.setText(email);

        editprofiles.setText("Updates");
        editprofiles.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editprofilesActionPerformed(evt);
            }
        });
        jLabel10.setText("Company Name");

        flcompaname.setText(companyname);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout
                .setHorizontalGroup(jPanel3Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(
                                jPanel3Layout
                                        .createSequentialGroup()
                                        .addGap(19, 19, 19)
                                        .addGroup(
                                                jPanel3Layout
                                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                        .addComponent(jLabel10).addComponent(jLabel6)
                                                        .addComponent(jLabel7).addComponent(jLabel8)
                                                        .addComponent(jLabel9).addComponent(jLabel11)
                                                        .addComponent(jLabel19))
                                        .addGap(18, 18, 18)
                                        .addGroup(
                                                jPanel3Layout
                                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addGroup(
                                                                jPanel3Layout
                                                                        .createSequentialGroup()
                                                                        .addGroup(
                                                                                jPanel3Layout
                                                                                        .createParallelGroup(
                                                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                                                        .addComponent(flsex)
                                                                                        .addComponent(flname))
                                                                        .addPreferredGap(
                                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                                                118, Short.MAX_VALUE)
                                                                        .addComponent(editprofiles))
                                                        .addGroup(
                                                                jPanel3Layout
                                                                        .createSequentialGroup()
                                                                        .addGroup(
                                                                                jPanel3Layout
                                                                                        .createParallelGroup(
                                                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                                                        .addComponent(flcompaname)
                                                                                        .addComponent(flemail)
                                                                                        .addComponent(flnumber)
                                                                                        .addComponent(fladdress)
                                                                                        .addComponent(flbirthday))
                                                                        .addGap(0, 183, Short.MAX_VALUE)))));
        jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(
                        jPanel3Layout
                                .createSequentialGroup()
                                .addGroup(
                                        jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jLabel6).addComponent(flname).addComponent(editprofiles))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(
                                        jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jLabel10).addComponent(flcompaname))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(
                                        jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(flsex).addComponent(jLabel7))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(
                                        jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jLabel8).addComponent(flbirthday))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(
                                        jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(fladdress)
                                                .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.TRAILING))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(
                                        jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jLabel11).addComponent(flnumber))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(
                                        jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jLabel19).addComponent(flemail))));

        btexit.setText("Exit");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(
                        layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(
                                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(
                                                        layout.createSequentialGroup()
                                                                .addGroup(
                                                                        layout.createParallelGroup(
                                                                                javax.swing.GroupLayout.Alignment.TRAILING)
                                                                                .addComponent(
                                                                                        jPanel3,
                                                                                        javax.swing.GroupLayout.Alignment.LEADING,
                                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                        Short.MAX_VALUE)
                                                                                .addComponent(
                                                                                        jPanel1,
                                                                                        javax.swing.GroupLayout.Alignment.LEADING,
                                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                        Short.MAX_VALUE)
                                                                                .addComponent(
                                                                                        jPanel2,
                                                                                        javax.swing.GroupLayout.Alignment.LEADING,
                                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                        Short.MAX_VALUE))
                                                                .addContainerGap())
                                                .addGroup(
                                                        javax.swing.GroupLayout.Alignment.TRAILING,
                                                        layout.createSequentialGroup().addComponent(btexit)
                                                                .addGap(25, 25, 25)))));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(btexit)
                        .addGap(5, 5, 5)));

        pack();
    }

    private void editpassActionPerformed(java.awt.event.ActionEvent evt) {
        EditPassword editpas = new EditPassword(null, true);
        editpas.setIdaccount1(chua1);
        editpas.setVisible(true);
    }

    private void editprofilesActionPerformed(java.awt.event.ActionEvent evt) {
        EditClient ea = new EditClient(null, true, flname.getText(), flcompaname.getText(), flsex.getText(), flbirthday.getText(), fladdress.getText(), flnumber.getText(), flemail.getText());
        ea.setId(chua1);
        ea.setVisible(true);
    }

    private void btnUnitActionPerformed(java.awt.event.ActionEvent evt) {
        MyUnit myunit = new MyUnit(null, true, chua1);
        myunit.setVisible(true);
    }

    /**
     * @param args
     *            the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        // <editor-fold defaultstate="collapsed"
        // desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase
         * /tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MyProfiles.class.getName())
                    .log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MyProfiles.class.getName())
                    .log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MyProfiles.class.getName())
                    .log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MyProfiles.class.getName())
                    .log(java.util.logging.Level.SEVERE, null, ex);
        }
        // </editor-fold>

        /*
         * Create and display the dialog
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                MyProfiles dialog = new MyProfiles(new javax.swing.JFrame(), true, "1", "1");
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify
    private javax.swing.JButton btnUnit;
    private javax.swing.JButton editpass;
    private javax.swing.JButton editprofiles;
    private javax.swing.JLabel  fladdress;
    private javax.swing.JLabel  flbirthday;
    private javax.swing.JLabel  flcmnd;
    private javax.swing.JLabel  flemail;
    private javax.swing.JLabel  flgroupname;
    private javax.swing.JLabel  flloginname;
    private javax.swing.JLabel  flname;
    private javax.swing.JLabel  flnumber;
    private javax.swing.JLabel  flpassword;
    private javax.swing.JLabel  flsex;
    private javax.swing.JLabel  jLabel1;
    private javax.swing.JLabel  jLabel11;
    private javax.swing.JLabel  jLabel19;
    private javax.swing.JLabel  jLabel10;
    private javax.swing.JLabel  jLabel2;
    private javax.swing.JLabel  jLabel3;
    private javax.swing.JLabel  jLabel4;
    private javax.swing.JLabel  jLabel6;
    private javax.swing.JLabel  jLabel7;
    private javax.swing.JLabel  jLabel8;
    private javax.swing.JLabel  jLabel9;
    private javax.swing.JPanel  jPanel1;
    private javax.swing.JPanel  jPanel2;
    private javax.swing.JPanel  jPanel3;
    private javax.swing.JLabel  flcompaname;
    private javax.swing.JButton btexit;
    // End of variables declaration
}
